package imnu.th.tongxin;

/**
 * @author: lys
 * @类名: Chid
 * @Title:
 * @date: 2020/7/22
 **/
public class Chid extends Thread {
    private Kitchen kitchen;
    //有多少 体力值
    private int hp = 0;
    //什么时候吃饱 健康值
    private int health;

    public Chid() {
    }
    public Chid(String name, Kitchen kitchen, int health) {
        super(name);
        this.kitchen = kitchen;
        this.health = health;
    }

    //吃饭
    public void eat() {
        try {
            this.kitchen.do_eat();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void run() {
        //当体力值小于健康值时，说明他没吃饱，可以一直吃，直到吃饱为止
        while (this.hp < this.health){
            this.eat();
        }
        System.out.println(Thread.currentThread().getName()+"吃饱了！");
        System.out.println();
    }

    public Kitchen getKitchen() {
        return kitchen;
    }

    public void setKitchen(Kitchen kitchen) {
        this.kitchen = kitchen;
    }

    public int getHp() {
        return hp;
    }

    public void setHp(int hp) {
        this.hp = hp;
    }

    public int getHealth() {
        return health;
    }

    public void setHealth(int health) {
        this.health = health;
    }
}
